package com.example.demo.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.Mapper.BlogMapper;
import com.example.demo.pojo.Blog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogServiceImpl implements BlogService {
    @Autowired
    private BlogMapper mapper;
    @Override
    public List<Blog> listBlogTopTen() {
        return mapper.getBloglistTop10();
    }

    @Override
    public Blog selectBlogById(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public Integer InsertBlog(Blog blog) {
        return mapper.insert(blog);
    }

    @Override
    public Integer DeleteBlog(Integer id) {
        return mapper.deleteById(id);
    }

    @Override
    public Integer UpdateBlog(Integer id, Blog blog) {

        return mapper.updateById(blog);
    }

    @Override
    public IPage<Blog> listBlog(Integer list) {
        IPage<Blog> userPage = new Page<>(list, 200);//参数一是当前页，参数二是每页个数
        userPage = mapper.selectPage(userPage, null);
        return userPage;
    }

    @Override
    public List<Blog> listBlogSearch(String title) {
        List<Blog> blogs = mapper.getSearch(title);
        return blogs;
    }
}
